<script setup>
  import { Suspense } from 'vue'
  import { collectOptions } from '@/helpers/context.js'
  import CompanyFormComponent from '@/components/company/CompanyFormComponent.vue'

  const options = collectOptions()
  const redirectOnsave = (company) => {
    window.location.replace('/companies/' + company.id)
  }

  const redirectOnCancel = () => {
    console.log('come_from', options)
    if (options['come_from']) {
      window.location.replace(options['come_from'])
    } else {
      window.location.href = options.context_url.replace('/api/v1/', '/')
    }
  }
</script>

<template>
  <Suspense>
    <div>
      <CompanyFormComponent
        :edit="options.edit"
        :companyId="options.company_id"
        :url="options.context_url"
        :formConfigUrl="options.form_config_url"
        @saved="redirectOnsave"
        @cancel="redirectOnCancel"
      />
    </div>
    <template #fallback> Chargement... </template>
  </Suspense>
</template>
